package com.hxj.common.core.util;

import com.hxj.common.core.pojo.bo.user.SecurityUser;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * @Author hxj
 * @Date 2024/10/26 15:10
 * @Description
 */
public class SecurityUtil {

    public static SecurityUser getLoginUser() {
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        SecurityUser securityUser;
        if ("anonymousUser".equals(principal.toString())) {

            //临时
            securityUser = new SecurityUser();
//            UserDTO user = new UserDTO(null, "超级用户");
//            securityUser.setUser(user);

        } else {
            securityUser = (SecurityUser) principal;
        }

        return securityUser;
    }

    public static Long getLoginUserId() {
//        SecurityUser loginUser = getLoginUser();
//        User user = loginUser.getUser();
//        return user.getId;
        // TODO
        return 0L;
    }

}
